//
//  NSLottieView.swift
//  Meboo
//
//  Created by kyo on 2024/5/7.
//

import UIKit

import Lottie
@objcMembers class NSLottieView: LottieAnimationView {
    
    func defultSet(name: String,loop: Bool) {
        let  animation = LottieAnimation.named(name,animationCache: DefaultAnimationCache.sharedCache)
        self.animation = animation
        self.loopMode = .loop
        self.animationSpeed = 1.0
        self.loopMode = .playOnce
        self.backgroundBehavior = .pauseAndRestore
        if loop {
            self.loopMode = .loop
        }
    }
    
    func stopAnimation() {
        self.stop()
    }
    
    func startAnimation(completionBlock: LottieCompletionBlock? = nil) {
        self.currentProgress = 0;
        self.play { completed in
            if completed {
                completionBlock!(completed)
            }
        }
    }
    
    func resetProgress(progress: CGFloat) {
        self.currentProgress = progress;
    }
}
